package cn.dlc.com.account.controller;

import cn.dlc.com.account.entity.Account;
import cn.dlc.com.account.service.AccountService;
import cn.dlc.com.log.entity.AccountChangeEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 邓立川
 * @date 2021/1/12 15:57
 * @desc 添加当前类的描述信息
 */
@RestController
@RequestMapping("bank1")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @PostMapping("transfer")
    public String transfer(@RequestBody AccountChangeEvent accountChangeEvent){
        try{
            if(accountChangeEvent != null) {
                // 这个转账的本质就是先发送一条消息
                accountService.sendMsg(accountChangeEvent);
            }
            return "ok";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }
}
